package cn.tedu.application.controller;

import cn.tedu.application.pojo.dto.ApplicationQuery;
import cn.tedu.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.application.pojo.entity.Application;
import cn.tedu.application.service.ApplicatinService;
import cn.tedu.attendance.pojo.vo.PageResult;
import cn.tedu.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/application")
public class ApplicationController {
    @Autowired
    private ApplicatinService applicatinService;
    @GetMapping("/list")
    public List<Application> selectAll(){
        return applicatinService.selectAll();
    }

    //分页查询
    @PostMapping("/page")
    public PageResult<Application> pageQuery(@RequestBody ApplicationQuery applicationQuery){
        return applicatinService.pageQuery(applicationQuery);
    }

    @PostMapping("/save")
    public JsonResult saveApplication(@RequestBody ApplicationSaveParam applicationSaveParam){
        log.debug("保存用户,applicationSaveParam={}",applicationSaveParam);
        applicatinService.save(applicationSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("/cancel/{id}")
    public JsonResult cancel(@PathVariable Long id){
        log.debug("撤销申请单:id={}",id);
        applicatinService.cancel(id);
        return JsonResult.ok();
    }

}
